<template>
  <div class="page-content-base">
    <div class="page-content-title">
     <div class="page-content-title-search">
       <a-space>
          <a-button type="primary" @click="ClickBack">返回管理界面</a-button>
       </a-space>
      </div>
      <h3 class="page-content-title-name">任务分配：类型>{{manager_type_name}}               任务号>{{mergeid}}</h3>
    </div>
    <div class="page-content-forms">
      <div style="margin-left: 10px;">
        <label>实施小组：</label>
        <a-select style="width: 240px" @change="orgSelectChange" allowClear v-model="org" option-label-prop="label">
          <a-select-option :value="item.id" :label="item.name" v-for="(item,index) in $store.state.orgs" :key="index">{{item.name}}</a-select-option>
        </a-select>
      </div>
      <div style="margin-left: 10px;">
        <label>实施角色：</label>
        <a-select style="width: 240px" @change="roleSelectChange" allowClear v-model="role" option-label-prop="label">
          <a-select-option :value="item.id" :label="item.name" v-for="(item,index) in $store.state.roles" :key="index">{{item.name}}</a-select-option>
        </a-select>
      </div>
      <div style="margin-left: 10px;">
        <label>实施人员：</label>
        <a-select style="width: 160px" @change="NameSelectChange" allowClear v-model="qs_form.name">
          <a-select-option :value="item.fullname" v-for="(item,index) in getActiveUsers" :key="index">{{item.fullname}}</a-select-option>
        </a-select>
      </div>
      <div class="page-content-title-search" style="position: absolute;right: 100px;">
       <a-space>
          <a-button type="primary" @click="ClickSearch">查询</a-button>
       </a-space>
      </div>
    </div>
    <div class="page-content-table" style="margin-top: 10px;">
      <a-table :columns="columns" :data-source="task_one_table_data" bordered :pagination="task_one_pagination"  size="small"
      @change="changeEvent"
      :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onTableSelectChange }"
      >
        <p slot="expandedRowRender" slot-scope="record" style="margin: 0">
          <a-descriptions title="其他信息" bordered="true" size="small"> 
            <a-descriptions-item label="前影像原始">{{record.jdcheck.tocog.preimage}}</a-descriptions-item>
            <a-descriptions-item label="前影像COG">{{record.jdcheck.tocog.precog}}</a-descriptions-item>
            <a-descriptions-item label="前影像URL">{{record.jdcheck.tocog.preimageurl}}</a-descriptions-item>
            <a-descriptions-item label="前影像状态">{{record.jdcheck.tocog.prepstatus}}</a-descriptions-item>
            <a-descriptions-item label="前影像错误信息" :span="2">{{record.jdcheck.tocog.prepmsg}}</a-descriptions-item>


             <a-descriptions-item label="后影像原始">{{record.jdcheck.tocog.lstimage}}</a-descriptions-item>
            <a-descriptions-item label="后影像COG">{{record.jdcheck.tocog.lstcog}}</a-descriptions-item>
            <a-descriptions-item label="后影像URL">{{record.jdcheck.tocog.lstimageurl}}</a-descriptions-item>
            <a-descriptions-item label="后影像状态">{{record.jdcheck.tocog.lstostatus}}</a-descriptions-item>
            <a-descriptions-item label="后影像错误信息" :span="2">{{record.jdcheck.tocog.lstpmsg}}</a-descriptions-item>
  <!-- :span="2" -->
            <a-descriptions-item label="影像中心">{{record.jdcheck.tocog.imagecenter}}</a-descriptions-item>
          </a-descriptions>
        </p>
        <span slot="mergeid" slot-scope="text, record"> 
          <span class="menu-name"  style="user-select: text;">{{record.mergeid}}</span>
        </span>
        <span slot="num" slot-scope="text, record"> 
          <span class="menu-name"  style="user-select: text;">{{record.num}}</span>
        </span>
        <span slot="utime" slot-scope="text, record"> 
          <span class="menu-name">{{GetTime(record.utime)}}</span>
        </span>

        <span slot="name" slot-scope="text, record">
          <span class="menu-name" >{{record.jdcheck.name}}</span>
        </span>
        <span slot="prepstatus" slot-scope="text, record">
          <span class="menu-name" >{{record.jdcheck.tocog.prepstatus=="1"?"有":"无"}}</span>
        </span>
        <span slot="lstpstatus" slot-scope="text, record">
          <span class="menu-name" >{{record.jdcheck.tocog.lstpstatus=="1"?"有":"无"}}</span>
        </span>
        <span slot="imagecenter" slot-scope="text, record">
          <span class="menu-name" >{{record.jdcheck.tocog.imagecenter}}</span>
        </span>
        <span slot="status" slot-scope="text, record"> 
          <a-badge :color="GetFenPeiStatusColor(record.jdcheck.status)" :text="GettFenPeiStatusFor(record) " />
        </span>
        <span slot="operation" slot-scope="text, record">
          <a-button class="operation-a" type="link" :disabled="!(record.jdcheck.status==-2)" @click="FenPeiAdmin(record['mergeid'])"  v-show="can_fenpei">分配</a-button>
        </span>
      </a-table>
    </div>
    <a-modal v-model="fenpei_visible" title="勾选分配" 
      @ok="fenpei_ok"
      :maskClosable="false"
      okText="分配"
      okType="dashed"
      :destroyOnClose="true"
      cancelText='取消'
      cancelokType="dashed"
      @cancel="fenpei_cancle"
      >
      <a-row>
        <span  v-show="codes.length>1">已选择了{{codes.length}}个图斑.分配给</span>
        <span  v-show="codes.length==1">已选择了编号{{codes[0]}}图斑.分配给</span>
      </a-row>
      <a-row>
        <label>实施人员：</label>
        <a-select style="width: 120px"  allowClear v-model="fenpei_name">
          <a-select-option :value="item.fullname" v-for="(item,index) in getActiveUsers" :key="index">{{item.fullname}}</a-select-option>
        </a-select>
      </a-row>
    </a-modal>
  </div>
</template>
<script>
export default {
  data() {
    return {
      mergeid:'', //外部传入
      can_fenpei:false,
      manager_type_name:"执法服务",//外部传入
      manager_task_type:"bigdata",//外部传入
      columns:[
        {
            title: '任务ID',
            scopedSlots: { customRender: 'mergeid' },
            key: 'code',
            width:280,
            align:'center'
        },
        {
            title: '数据量',
            scopedSlots: { customRender: 'num' },
            key: 'code',
            width:80,
            align:'center'
        },
        {
            title: '任务发起时间',
            scopedSlots: { customRender: 'utime' } ,
            width:180,
            align:'center'
        },

        {
            title: '实施人员',
            scopedSlots: { customRender: 'name' },
            width:140,
            align:'center'
        },
        {
            title: '前期服务',
            scopedSlots: { customRender: 'prepstatus' } ,
            width:110,
            align:'center'
        },
        {
            title: '后期服务',
            scopedSlots: { customRender: 'lstpstatus' } ,
            width:110,
            align:'center'
        },
        {
            title: '视角中心',
            scopedSlots: { customRender: 'imagecenter' } ,
            width:280,
            align:'center'
        },
        {
            title: '状态',
            scopedSlots: { customRender: 'status' } ,
            width:210,
            align:'center'
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'operation' },
          align:'center'
        },
      ],
      task_one_table_data:[],
      task_one_pagination:{
        size:'small',
        pageSize:10,
        total:0,
        showTotal:(total, range)=>{
          return `共 ${total} 个，当前${range[0]}-${range[1]}`
        },
      },
      
      selectedRowKeys:[],
      qs_form:{
        code:'',
        name:'',
        status:'',
        taskid:''
      },
      fenpei_visible:false,
      fenpei_name:'',
      codes:[],


      org:undefined,
      role:undefined,

      fenpei_in_visible:false,
      num_from:'',
      num_to:'',
      pic_visible:false,
      pic_imgsrc:'',
      pic_name:'',
      map_visible:false,
      Drawer_title:"",
    }
  },
  components: {
      show_png: () => import("@/components/router/show_png.vue"),
    },
  mounted() {
    this.$mitt.$on('task_manager_jdcheckfenpei_taskid', (mergeid,can_fenpei) => {
      this.mergeid=mergeid
      this.can_fenpei=can_fenpei
      this.selectedRowKeys=[]
      this.manager_task_type=manager_task_type
      this.manager_type_name=this.$common_apis.Get_task_type_name(manager_task_type)
      this.ClickSearch()
    })  
    this.GetUser();
  },
  beforeDestroy() {
      this.$mitt.$off('task_manager_jdcheckfenpei_taskid');
    },
  computed:{
    getActiveUsers(){
        return this.$store.state.users
      }
    },
  methods: {
    GetTimeFor(record){
      if(this.qs_form.status<=2){
        return this.GetTime(record.properties[this.$store.state.task_type].time)
      }
      else if(this.qs_form.status==3){
        return "NAN"
      }
      else if(this.qs_form.status==4 || this.qs_form.status==5){
        return "NAN"
      }
      else if(this.qs_form.status==6){
        return this.GetTime(record.properties[this.$store.state.task_type].fuzhi.time)
      }
      else{
        return this.GetTime(record.properties[this.$store.state.task_type].time)
      }
    },
    orgSelectChange(value){
      this.qs_form.name=""
      this.GetUser(value,this.role)
      this.$forceUpdate()
    },
    roleSelectChange(value){
      this.qs_form.name=""
      this.GetUser(this.org,value)
      this.$forceUpdate()
    },
    onChangeCode(e){
      this.search();
    },
    ClickSearch(){
      this.search();
    },
    ClickBack(){
      this.$mitt.emit('task_manager_show',1);
      this.$mitt.emit('task_manager_fenpei_back');
    },
    NameSelectChange(){
      this.search();
    },
    StatusSelectChange(){
      this.search();
    },
    search(pagenum=1){
      this.task_one_table_data=[]
      let qs={
        pagesize:this.task_one_pagination.pageSize,
        pagenum,
        mergeid:this.mergeid,
        optype:this.manager_task_type
      }
      if(this.qs_form.code!=""){
        qs.code=this.qs_form.code
      }
      if(this.qs_form.name !=""){
        qs.name=this.qs_form.name
      }
      if(this.qs_form.taskid !=""){
        qs.taskid=this.qs_form.taskid
      }
      this.$common_apis.axios_get("/search_task?",qs)
      .then(res => {
        if(res ){
          let task_one_table_data=[]
          res.data.forEach((_featrue,index)=>{
            _featrue.key=index
          })
          task_one_table_data=res.data
          this.task_one_table_data=task_one_table_data
          this.task_one_pagination.total=res.page.count
        }
      });
    },
    GettFenPeiStatusFor(record){
      if(this.qs_form.status<=2){
        return this.GettFenPeiStatus(record.jdcheck.status)
      }
      else if(this.qs_form.status==3){
        return "大数据"
      }
      else if(this.qs_form.status==4 || this.qs_form.status==5){
        return "大数据"
      }
      else if(this.qs_form.status==6){
        return this.GettFenPeiStatus(record.jdcheck.status,"task_fuzhis")
      }
      else{
        return this.GettFenPeiStatus(record.jdcheck.status)
      }
    },
    GettFenPeiStatus(status,_status="detail_status"){
      let status_index=this.$store.state[_status].findIndex((_detail_status)=>{
        if(_detail_status.status){
          return _detail_status.status==status
        }
        else if(_detail_status.code){
          return _detail_status.code==status
        }
        
      })
      if(status_index>=0){
        return this.$store.state[_status][status_index].name
      }
      else{
        return ""
      } 
    },
    GetFenPeiStatusColor(status){
      let status_Color="";
      if(status==-2){
        status_Color="gray"
      }
      else if(status==-1){
        status_Color="red"
      }
      else {
        status_Color="green"
      }
      return status_Color
    },
    onTableSelectChange(selectedRowKeys){
      this.selectedRowKeys = selectedRowKeys;
    },
    ClickFenPeiGouXuan(){
      if(this.selectedRowKeys.length==0){
        this.$message.info('没有选择图斑，至少需要选择一个');
        return false
      }
      let codes=[]
      this.selectedRowKeys.forEach((_featrue,index)=>{
        codes.push(this.task_one_table_data[_featrue]['_id'])
      })
      this.FenPeiAdminPost(codes);
    },
    async FenPeiAdminPost(codes){
      this.codes=codes
      this.fenpei_name=''
      this.fenpei_visible=true
      this.WaitFenPeiName =new Promise((resolve)=>{this.WaitFenPeiName_resolve=resolve;});
      let FenPeiNameOK=await this.WaitFenPeiName
      if(FenPeiNameOK){
        this.$common_apis.axios_post("/update_jbcheck_admin?",{
          mergeid:this.mergeid,
          name:this.fenpei_name,
        },true)
        .then(res => {
          if (res) {
            this.search(this.task_one_pagination.ucurrent);
          }
        });
        return true
      }
      return false
    },
    fenpei_ok(){
      if(this.fenpei_name){
        this.WaitFenPeiName_resolve(true);
        this.fenpei_visible=false
      }
      else{
        this.$message.info('没有选择分配给谁呢');
        return false
      }
      
    },
    fenpei_cancle(){
      this.fenpei_visible=false
      this.WaitFenPeiName_resolve(false);
    },
    ClickFenPeiIn(){
      this.FenPeiAdminPostIn();
    },
    async FenPeiAdminPostIn(){
      this.fenpei_in_visible=true
      this.fenpei_name=''
      this.WaitFenPeiNameIn =new Promise((resolve)=>{this.WaitFenPeiNameIn_resolve=resolve;});
      let FenPeiNameOK=await this.WaitFenPeiNameIn
      if(FenPeiNameOK){
        this.$common_apis.axios_post("/update_admin?",{
          mergeid:this.mergeid,
          name:this.fenpei_name,
          from:this.num_from-0,
          to:this.num_to-0,
          status:this.qs_form.status,
          optype: this.manager_task_type
        },true)
        .then(res => {
          if (res) {
            this.search(this.task_one_pagination.ucurrent);
          }
        });
        return true
      }
      return false
    },
    fenpei_in_ok(){
      let ok=false
      this.num_from=this.num_from-0
      this.num_to=this.num_to-0
      if(this.num_from>0 && this.num_to>0 &&this.num_from <=this.num_to){
        ok=true
      }
      else{
        this.$message.info('必须是数字,并且第一个应不大于第二个数字');
        return false
      }
      if(this.fenpei_name){
        ok=true
      }
      else{
        this.$message.info('没有选择分配给谁呢');
        return false
      }
      if(ok){
        this.WaitFenPeiNameIn_resolve(true);
        this.fenpei_in_visible=false
      }
    },
    fenpei_in_cancle(){
      this.fenpei_in_visible=false
      this.WaitFenPeiNameIn_resolve(false);
    },
    FenPeiAdmin(code){
      this.FenPeiAdminPost([code])
    },
    changeEvent(pagination){
      this.selectedRowKeys=[]
      this.search(pagination.current)
      this.task_one_pagination.ucurrent=pagination.current
    },
    name_filter(input, option) {
      return (
        option.componentOptions.children[0].text.indexOf(input) >= 0
      );
    },
    handleView(imgsrc,a,b,c) {
      this.pic_imgsrc = imgsrc;
      this.pic_visible = true;
      this.pic_name=`预览图片:${a}-${b}-${c}`
    },
    
    CloseModel() {
      this.map_visible = false;
    },
  }
}
</script>
<style>
.showimg .demo-upload-list-cover{
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,.6);
}
.showimg:hover .demo-upload-list-cover{
    display: block;
}
.demo-upload-list-cover i{
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
    margin-top: calc(50% - 10px);
}
.map_drawer .ant-drawer-body{
  height: 100%;
}
</style>